<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="js/jquery-3.1.1.js"></script>
</head>
<body>
	<p>添加用户</p>
	<form action="user.do?method=addUser" method="post">
		<input type="text" name="username" placeholder="请输入用户名"><span id="msg"></span><br>
		<input type="text" name="realname" placeholder="请输入姓名"><br>
		<input type="text" name="address" placeholder="请输入地址"><br>
		<input type="text" name="tel" placeholder="请输入电话"><br>
		<input type="submit" value="添加">
	</form>
	<script type="text/javascript">
		//用户名失去焦点，进行重名判断
		$("[name=username]:text").blur(function(){
			$.post("user.do?method=checkUsername",
					{username:$(this).val()},
					function(text){
						if(text=='true'){
							$("#msg").css("color","blue").text("用户名可用");
						}else{
							$("#msg").css("color","red").text("用户名不可用！");
						}
					})
		});
	</script>
</body>
</html>